package com.lanou.zakerproject.community;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.VolleySingleton;

/**
 * Created by dllo on 16/1/13.
 */
public class FindAdapter extends BaseAdapter {
    private Context context;
    private TypeData data;

    public FindAdapter(Context context, TypeData data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.getData().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return data.getData().getList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_community_listview, parent, false);
            myViewHolder = new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        if (data != null) {
            ImageLoader.ImageListener listener = ImageLoader.getImageListener(myViewHolder.item_community_icon, R.mipmap.ic_launcher, R.mipmap.default_img_nonet);
            VolleySingleton.getImageLoader().get(data.getData().getList().get(position).getPic(), listener);
            myViewHolder.item_community_title.setText(data.getData().getList().get(position).getTitle());
            myViewHolder.item_community_content.setText(data.getData().getList().get(position).getStitle());
        }
        return convertView;
    }

    class MyViewHolder {
        private ImageView item_community_icon;
        private TextView item_community_title, item_community_content;

        public MyViewHolder(View view) {
            item_community_icon = (ImageView) view.findViewById(R.id.icon_community);
            item_community_title = (TextView) view.findViewById(R.id.community_title);
            item_community_content = (TextView) view.findViewById(R.id.community_content);
        }
    }


}
